import { contextBridge } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'

// 为渲染进程添加 自定义API
const api = {
  app: {
    versions: electronAPI.process.versions,
    platform: electronAPI.process.platform
  }
}

// 如果没有启用上下文隔离，则直接将其添加到全局Dom对象中
if (process.contextIsolated) {
  try {
    contextBridge.exposeInMainWorld('electron', {
      operate: (name) => electronAPI.ipcRenderer.send('win:operate', name)
    })
    contextBridge.exposeInMainWorld('api', api)
  } catch (error) {
    console.error(error)
  }
} else {
  window.electron = electronAPI
  window.api = api
}
